﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Logic;
using Entities;

namespace Presentation
{
	public partial class InfoLists : UserControl
	{
		public InfoLists()
		{
			InitializeComponent();
        }

        public void Initialize(Movie entity)
        {
            Tag = entity;
            FillData(entity);
        }

        public void FillData(Movie entity)
        {
            MovieBL mbl = new MovieBL();
            listBoxIsIn.DataSource = new BindingList<MovieList>(mbl.GetListsByMovie(entity, true));
            listBoxIsntIn.DataSource = new BindingList<MovieList>(mbl.GetListsByMovie(entity, false));
        }

        private void buttonRemoveFromList_Click(object sender, EventArgs e)
        {
            BindingList<MovieList> collectionlistBoxIsIn = (BindingList<MovieList>)(listBoxIsIn.DataSource);
            BindingList<MovieList> collectionlistBoxIsntIn = (BindingList<MovieList>)(listBoxIsntIn.DataSource);

            ListBL bl = new ListBL();
            if (bl.DeleteMovie((MovieList)listBoxIsIn.SelectedItem, (Movie)Tag))
            {
                collectionlistBoxIsntIn.Add((MovieList)(listBoxIsIn.SelectedItem));
                collectionlistBoxIsIn.Remove((MovieList)(listBoxIsIn.SelectedItem));
            }
        }

        private void buttonAddToList_Click(object sender, EventArgs e)
        {
            BindingList<MovieList> collectionlistBoxIsIn = (BindingList<MovieList>)(listBoxIsIn.DataSource);
            BindingList<MovieList> collectionlistBoxIsntIn = (BindingList<MovieList>)(listBoxIsntIn.DataSource);

            ListBL bl = new ListBL();
            if (bl.AddMovie((MovieList)listBoxIsntIn.SelectedItem, (Movie)Tag))
            {
                collectionlistBoxIsIn.Add((MovieList)(listBoxIsntIn.SelectedItem));
                collectionlistBoxIsntIn.Remove((MovieList)(listBoxIsntIn.SelectedItem));
            }
        }
	}
}